<template>
  <view class="distribution" @click="toAddress">
    <template v-if="address && address.id">
      <view class="distribution-top">
        <view class="distribution-address"
          >{{ address.province }}{{ address.city }}{{ address.district }}</view
        >
        <view class="distribution-addressdetails">
          <view class="addressdetails">{{ address.detail }}</view>

          <i
            class="iconfont icon-arrow-right"
            style="font-size: 22rpx; color: #cdcdcd"
          ></i>
        </view>
        <view class="distribution-name">
          <view>{{ address.name }}</view>
          <view>{{ address.mobile | noPassByMobile }}</view>
        </view>
        <view class="distribution-method" v-if="showPickUpBySelf"
          >({{ $t("order.code") }})</view
        >
        <view v-show="isShop" class="select-shop">
          ({{$t('order.codeTake')}}）
        </view>
      </view>
      <image
        class="distribution-bottom"
        :src="asyncImgs.shopingcart.heng"
        mode="scaleToFill"
      ></image>
    </template>
    <template v-else>
      <view class="distribution-top">
        <view class="distribution-address">{{ $t("common.noAddress") }}</view>
        <view class="distribution-addressdetails">
          <view>{{ $t("common.chooseAddress") }}</view>
          <i
            class="iconfont icon-arrow-right"
            style="font-size: 22rpx; color: #cdcdcd"
          ></i>
        </view>
        <view v-show="isShop" class="select-shop">
          ({{$t('order.codeTake')}}）
        </view>
      </view>
      <image
        class="distribution-bottom"
        :src="asyncImgs.shopingcart.heng"
        mode="scaleToFill"
      ></image>
    </template>
  </view>
</template>

<script>
export default {
  data() {
    return {};
  },
  props: {
    address: {
      type: Object,
      default: function () {
        return null;
      },
    },
    send_type_arr: {
      type: Array,
      default: () => {
        return []
      },
    },
    isShop: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    showPickUpBySelf() {
      let arr = this.send_type_arr.filter((d) => {
        return d == true;
      });
      if (arr.length) return true;
      return false;
    },
  },
  filters: {
    noPassByMobile(str) {
      if (null != str && str != undefined) {
        var pat = /(\d{3})\d*(\d{4})/;
        return str.replace(pat, "$1****$2");
      } else {
        return "";
      }
    },
  },
  methods: {
    toAddress() {
      uni.navigateTo({
        url: "/user/my/addressmanage?is_order=1",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
view {
  color: #262626;
}

.distribution {
  position: relative;
  background-color: #ffffff;
}

.distribution-top {
  position: relative;
  padding: 40rpx 30rpx 32rpx;
  .icon-arrow-right {
		position: absolute;
		right: 30rpx;
		top: 50%;
		transform: translateY(0, -50%);
  }
  .distribution-address {
    line-height: 36rpx;
    font-size: 26rpx;
  }

  .distribution-addressdetails {
    margin-top: 20rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 34rpx;
    font-weight: bold;

    .addressdetails {
      width: 620rpx;
      color: #262626;
      line-height: 48rpx;
      word-break: break-all;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2; /* 这里是超出几行省略 */
      overflow: hidden;
    }

    image {
      width: 12rpx;
      height: 20rpx;
    }
  }

  .distribution-name {
    margin-top: 8rpx;
    display: flex;
    align-items: center;
    line-height: 36rpx;
    font-size: 26rpx;
    view {
      margin-right: 12rpx;
    }
  }

  .distribution-method {
    margin-top: 18rpx;
    font-size: 24rpx;
    color: #f7271f;
  }
}

.distribution-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 750rpx;
  height: 6rpx;
  display: block;
}
.select-shop {
  margin-top: 8rpx;
  font-size: 24rpx;
  line-height: 34rpx;
  color: #f0250e;
}
</style>
